﻿using System;

namespace AiAsteriods.Game.Entities.Agent {
  static class MNodeFactory {
    private static MNode[] nodes;
    private static int nodeIndex;
    private static int nodeCount;

    public static void Init() {
      nodeCount = (int)(Math.Pow(MNode.numActions, Global.GameStart.Config.MaxDepth) + 1);
      nodes = new MNode[nodeCount];
      for (int i = 0; i < nodeCount; i++)
        nodes[i] = new MNode();
      nodeIndex = 0;
    }

    public static MNode Get() {
      nodeIndex++;
      nodeIndex %= nodeCount;
      nodes[nodeIndex].Reset();
      return nodes[nodeIndex];
    }
  }
}
